package cn.yh.springbootjwt.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel(value = "统一返回结果")
public class AjaxResult<T> {
    @ApiModelProperty(value = "提示信息")
    private String msg;
    @ApiModelProperty(value = "状态码")
    private Integer code;
    @ApiModelProperty(value = "返回数据")
    private T data;

    public AjaxResult(String msg, Integer code, T data) {
        this.msg = msg;
        this.code = code;
        this.data = data;
    }
/*
* 成功返回结果
* @param msg
* @param code
* @param data
* @return*/
    public static AjaxResult success(String msg, Integer code, Object data) {
        return new AjaxResult(msg, code, data);
    }

    /* 成功返回结果
     * @param msg
     * @param code
     * @param data
     * @return*/
    public static AjaxResult success( Object data) {
        return new AjaxResult("操作成功", 200, data);
    }

    /* 成功返回结果
     * @param msg
     * @param code
     * @param data
     * @return*/
    public static AjaxResult success() {
        return new AjaxResult("操作成功", 200, null);
    }

    public static AjaxResult success(String token, String msg) {
        return new AjaxResult(msg, 200, token);
    }
    /*
     * 成功返回结果
     * @param msg
     * @param code
     * @param data
     * @return*/
    public static AjaxResult error(String msg) {
        return new AjaxResult(msg, 500, null);
    }

    /* 成功返回结果
     * @param msg
     * @param code
     * @param data
     * @return*/
    public static AjaxResult error( Object data, String msg) {
        return new AjaxResult(msg, 500, data);
    }
    /* 成功返回结果
     * @param msg
     * @param code
     * @param data
     * @return*/
    public static AjaxResult error( Object data, String msg, Integer code) {
        return new AjaxResult(msg, code, data);
    }

    /* 成功返回结果
     * @param msg
     * @param code
     * @param data
     * @return*/
    public static AjaxResult error() {
        return new AjaxResult("操作失败", 500, null);
    }


    public static AjaxResult error(  String msg, Integer code) {
        return new AjaxResult(msg, code,null);
    }

    public static AjaxResult verifyFail(String msg) {
        return new AjaxResult(msg, 401, null);
    }
}
